﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Data;
using Jy123.DBUtility;
using Jy123.Common;

namespace Jy123.BLL.Public
{
    public class State
    {
        private State_Record BLLState = new State_Record();
        private Model.State_Record record = new Jy123.Model.State_Record();
        /// <summary>
        /// 竞猜
        /// </summary>
        /// <param name="user">用户</param>
        /// <param name="friend">对竞猜做动作时，friend该竞猜的发起者。如果是发起竞猜，该参数为null</param>
        /// <param name="guess">竞猜</param>
        /// <param name="actionType">执行动作的类型</param>
        public void CreateGuessState(Model.User_Main user, Model.User_Main friend, Model.User_Guess_Main guess, int actionType)
        {
            record.ActionType = Convert.ToInt32(Jy123.BLL.Public.EnumConfig.StateType.Guess);
            record.CTime = DateTime.Now;
            record.FUser = user.ID.ToString();
            record.UserName = user.UserName;
            if (friend != null)
            {
                record.FFriend = friend.ID;
                record.FriendName = friend.UserName;
            }
            record.FResult = guess.ID.ToString();
            record.ResultName = guess.Title;
            record.FState = actionType;
            BLLState.Add(record);
        }

        /// <summary>
        /// 用户操作相册
        /// </summary>
        /// <param name="user">用户</param>        
        ///<param name="album">相册</param>
        public void CreateAlbumState(Model.User_Main user, Model.User_Album album, int actionType)
        {
            record.ActionType = Convert.ToInt32(Jy123.BLL.Public.EnumConfig.StateType.User);
            record.CTime = DateTime.Now;
            record.FUser = user.ID.ToString();
            record.UserName = user.UserName;
            record.FResult = album.ID.ToString();
            record.ResultName = album.Title;
            record.FAlbum = album.ID;
            record.AlbumName = album.Title;
            record.FState = actionType;
            BLLState.Add(record);
        }

        /// <summary>
        /// 用户添加照片
        /// </summary>
        /// <param name="user">用户</param>        
        ///<param name="album">相册</param>
        ///<param name="strPId">照片ID字符串</param>
        ///<param name="strPName">照片名称字符串</param>
        public void CreatePhotoState(Model.User_Main user, Model.User_Album album, string strPId, string strPName)
        {
            int actionType = Convert.ToInt32(Public.EnumConfig.StateActionType.CreatePhoto);
            record.ActionType = Convert.ToInt32(Jy123.BLL.Public.EnumConfig.StateType.User);
            record.CTime = DateTime.Now;
            record.FUser = user.ID.ToString();
            record.UserName = user.UserName;
            record.FResult = strPId;
            record.ResultName = strPName;
            record.FAlbum = album.ID;
            record.AlbumName = album.Title;
            record.FState = actionType;
            BLLState.Add(record);
        }

        /// <summary>
        /// 用户添加照片评论
        /// </summary>
        /// <param name="user">用户</param>
        /// <param name="friend">照片主人</param>
        ///<param name="photo">照片</param>
        ///<param name="comment">评论</param>        
        public void CreateCommentPhotoState(Model.User_Main user, Model.User_Main friend, Model.User_Photo photo, Model.Photo_Comment comment)
        {
            int actionType = Convert.ToInt32(Public.EnumConfig.StateActionType.CommentPhoto);
            record.ActionType = Convert.ToInt32(Jy123.BLL.Public.EnumConfig.StateType.User);
            record.CTime = DateTime.Now;
            record.FUser = user.ID.ToString();
            record.UserName = user.UserName;
            record.FFriend = friend.ID;
            record.FriendName = friend.UserName;
            record.FResult = comment.ID.ToString();
            //此处将表的相册字段复用为照片ID和照片链接
            record.FAlbum = photo.ID;
            record.AlbumName = photo.FilePath;
            record.FState = actionType;
            BLLState.Add(record);
        }

        /// <summary>
        /// 用户创建日志
        /// </summary>
        /// <param name="user">用户</param>        
        ///<param name="blog">日志</param>
        public void CreateBlogState(Model.User_Main user, Model.User_Blog blog)
        {
            int actionType = Convert.ToInt32(Public.EnumConfig.StateActionType.CreateBlog);
            record.ActionType = Convert.ToInt32(Jy123.BLL.Public.EnumConfig.StateType.User);
            record.CTime = DateTime.Now;
            record.FUser = user.ID.ToString();
            record.UserName = user.UserName;
            record.FResult = blog.ID.ToString();
            record.ResultName = blog.Title;
            record.FState = actionType;
            BLLState.Add(record);
        }

        /// <summary>
        /// 用户创建日志评论
        /// </summary>
        /// <param name="user">用户</param> 
        /// <param name="friend">日志主人</param>
        ///<param name="blog">日志</param>
        ///<param name="comment">评论</param>
        public void CreateCommentBlogState(Model.User_Main user, Model.User_Main friend, Model.User_Blog blog, Model.Blog_Comment comment)
        {
            int actionType = Convert.ToInt32(Public.EnumConfig.StateActionType.CommentBlog);
            record.ActionType = Convert.ToInt32(Jy123.BLL.Public.EnumConfig.StateType.User);
            record.CTime = DateTime.Now;
            record.FUser = user.ID.ToString();
            record.UserName = user.UserName;
            record.FFriend = friend.ID;
            record.FriendName = friend.UserName;
            //此处将表的相册字段复用为日志ID
            record.FAlbum = blog.ID;
            record.AlbumName = blog.Title;
            record.FResult = comment.ID.ToString();
            record.FState = actionType;
            BLLState.Add(record);
        }

        /// <summary>
        /// 用户创建心情
        /// </summary>
        /// <param name="user">用户</param>        
        ///<param name="mood">心情</param>
        public void CreateMoodState(Model.User_Main user, Model.User_Mood mood)
        {
            int actionType = Convert.ToInt32(Public.EnumConfig.StateActionType.CreateMood);
            record.ActionType = Convert.ToInt32(Jy123.BLL.Public.EnumConfig.StateType.User);
            record.CTime = DateTime.Now;
            record.FUser = user.ID.ToString();
            record.UserName = user.UserName;
            record.FResult = mood.ID.ToString();
            record.FState = actionType;
            BLLState.Add(record);
        }

        /// <summary>
        /// 用户创建心情评论
        /// </summary>
        /// <param name="user">用户</param> 
        /// <param name="friend">心情主人</param>
        ///<param name="mood">心情</param>
        ///<param name="comment">评论</param>
        public void CreateCommentMoodState(Model.User_Main user, Model.User_Main friend, Model.User_Mood mood, Model.User_MoodComment comment)
        {
            int actionType = Convert.ToInt32(Public.EnumConfig.StateActionType.CommentMood);
            record.ActionType = Convert.ToInt32(Jy123.BLL.Public.EnumConfig.StateType.User);
            record.CTime = DateTime.Now;
            record.FUser = user.ID.ToString();
            record.UserName = user.UserName;
            record.FFriend = friend.ID;
            record.FriendName = friend.UserName;
            //此处将表的相册字段复用为心情ID
            record.FAlbum = mood.ID;
            record.FResult = comment.ID.ToString();
            record.FState = actionType;
            BLLState.Add(record);
        }

        /// <summary>
        /// 用户创建组件或者升级组件
        /// </summary>
        /// <param name="user">用户</param>        
        ///<param name="module">组件</param>
        public void CreateModuleState(Model.User_Main user, Model.Module_Main module, int actionType)
        {
            record.ActionType = Convert.ToInt32(Jy123.BLL.Public.EnumConfig.StateType.Module);
            record.CTime = DateTime.Now;
            record.FUser = user.ID.ToString();
            record.UserName = user.UserName;
            record.FResult = module.ID.ToString();
            record.FState = actionType;
            BLLState.Add(record);
        }

        /// <summary>
        /// 进行比赛
        /// </summary>
        ///<param name="strUserId">参加比赛的用户ID字符串</param>
        ///<param name="strUserName">参加比赛的用户名字符串</param>
        ///<param name="friend">赛场主</param>
        ///<param name="venues">赛场</param>
        ///<param name="strClubId">参加比赛的俱乐部ID字符串</param>
        ///<param name="strClubName">参加比赛的俱乐部名字字符串</param>
        ///<param name="strRank">比赛结果排行字符串</param>
        ///<param name="strScore">比赛结果比分字符串</param>
        public void CreateRaceState(string strUserId, string strUserName, string strClubId, string strClubName, string strRank, string strScore, Model.User_Main friend, Model.Venues_Main venues)
        {
            int actionType = Convert.ToInt32(Public.EnumConfig.StateActionType.Race);
            record.ActionType = Convert.ToInt32(Jy123.BLL.Public.EnumConfig.StateType.Module);
            record.CTime = DateTime.Now;
            record.FUser = strUserId;
            record.UserName = strUserName;
            record.FVenues = venues.ID;
            record.VenuesName = venues.VName;
            record.FClub = strClubId;
            record.ClubName = strClubName;
            record.FResult = strRank;
            record.ResultName = strScore;
            record.FState = actionType;
            record.FFriend = friend.ID;
            record.FriendName = friend.UserName;
            BLLState.Add(record);
        }

        /// <summary>
        /// 进行训练
        /// </summary>
        ///<param name="strUserId">参加训练的用户ID字符串</param>
        ///<param name="strUserName">参加训练的用户名字符串</param>
        ///<param name="friend">训练中心主人</param>
        ///<param name="venues">训练中心</param>
        ///<param name="strClubId">参加训练的俱乐部ID字符串</param>
        ///<param name="strClubName">参加训练的俱乐部名字字符串</param>        
        public void CreateTrainState(string strUserId, string strUserName, string strClubId, string strClubName, Model.User_Main friend, Model.TCenter_Main venues)
        {
            int actionType = Convert.ToInt32(Public.EnumConfig.StateActionType.Training);
            record.ActionType = Convert.ToInt32(Jy123.BLL.Public.EnumConfig.StateType.Module);
            record.CTime = DateTime.Now;
            record.FUser = strUserId;
            record.UserName = strUserName;
            record.FVenues = venues.ID;
            record.VenuesName = venues.TName;
            record.FClub = strClubId;
            record.ClubName = strClubName;
            record.FState = actionType;
            record.FFriend = friend.ID;
            record.FriendName = friend.UserName;
            BLLState.Add(record);
        }

        /// <summary>
        /// 用户赠送礼物
        /// </summary>
        /// <param name="user">用户</param>        
        ///<param name="friend">接受者</param>
        ///<param name="gift">礼物</param>
        public void CreateSendGiftState(Model.User_Main user, Model.User_Main friend, Model.Public_Gift gift)
        {
            int actionType = Convert.ToInt32(Public.EnumConfig.StateActionType.SendGift);
            record.ActionType = Convert.ToInt32(Jy123.BLL.Public.EnumConfig.StateType.User);
            record.CTime = DateTime.Now;
            record.FUser = user.ID.ToString();
            record.UserName = user.UserName;
            record.FFriend = friend.ID;
            record.FriendName = friend.UserName;
            record.FResult = gift.ID.ToString();
            record.ResultName = gift.GName;
            record.FState = actionType;
            BLLState.Add(record);
        }

        /// <summary>
        /// 好友
        /// </summary>
        /// <param name="user">用户</param>        
        ///<param name="friend">好友</param>        
        public void CreateMakeFriendState(Model.User_Main user, Model.User_Main friend, int actionType)
        {
            record.ActionType = Convert.ToInt32(Jy123.BLL.Public.EnumConfig.StateType.User);
            record.CTime = DateTime.Now;
            record.FUser = user.ID.ToString();
            record.UserName = user.UserName;
            record.FFriend = friend.ID;
            record.FriendName = friend.UserName;
            record.FState = actionType;
            BLLState.Add(record);
        }

        /// <summary>
        /// 发起或参加投票
        /// </summary>
        /// <param name="user">用户</param>
        /// <param name="friend">对投票做动作时，friend该投票的发起者。如果是发起投票，该参数为null</param>
        /// <param name="vote">投票</param>
        /// <param name="actionType">是执行参加还是发起动作</param>
        public void CreateVoteState(Model.User_Main user, Model.User_Main friend, Model.User_Vote vote, int actionType)
        {
            record.ActionType = Convert.ToInt32(Jy123.BLL.Public.EnumConfig.StateType.User);
            record.CTime = DateTime.Now;
            record.FUser = user.ID.ToString();
            record.UserName = user.UserName;
            if (friend != null)
            {
                record.FFriend = friend.ID;
                record.FriendName = friend.UserName;
            }
            record.FResult = vote.ID.ToString();
            record.ResultName = vote.Title;
            record.FState = actionType;
            BLLState.Add(record);
        }

        /// <summary>
        /// 用户创建投票评论
        /// </summary>
        /// <param name="user">用户</param> 
        /// <param name="friend">投票的主人</param>
        ///<param name="vote">投票</param>
        ///<param name="comment">评论</param>
        public void CreateCommentVoteState(Model.User_Main user, Model.User_Main friend, Model.User_Vote vote, Model.User_VoteComm comment)
        {
            int actionType = Convert.ToInt32(Public.EnumConfig.StateActionType.CommentMood);
            record.ActionType = Convert.ToInt32(Jy123.BLL.Public.EnumConfig.StateType.User);
            record.CTime = DateTime.Now;
            record.FUser = user.ID.ToString();
            record.UserName = user.UserName;
            record.FFriend = friend.ID;
            record.FriendName = friend.UserName;
            //此处将表的相册字段复用为投票ID
            record.FAlbum = vote.ID;
            record.FResult = comment.ID.ToString();
            record.FState = actionType;
            BLLState.Add(record);
        }

        /// <summary>
        /// 用户升级
        /// </summary>
        /// <param name="user">用户</param>        
        ///<param name="level">等级</param>        
        public void CreateUpdateUserState(Model.User_Main user, Model.User_Level level)
        {
            int actionType = Convert.ToInt32(Public.EnumConfig.StateActionType.UpdateUser);
            record.ActionType = Convert.ToInt32(Jy123.BLL.Public.EnumConfig.StateType.User);
            record.CTime = DateTime.Now;
            record.FUser = user.ID.ToString();
            record.UserName = user.UserName;
            record.FResult = level.ID.ToString();
            record.ResultName = level.LevelName;
            record.FState = actionType;
            BLLState.Add(record);
        }

        /// <summary>
        /// 用户修改头像或者基本信息
        /// </summary>
        /// <param name="user">用户</param>        
        ///<param name="photo">头像,如果是修改基本信息那么photo为null</param>        
        public void CreateModifyUserState(Model.User_Main user, Model.User_Photo photo, int actionType)
        {
            record.ActionType = Convert.ToInt32(Jy123.BLL.Public.EnumConfig.StateType.User);
            record.CTime = DateTime.Now;
            record.FUser = user.ID.ToString();
            record.UserName = user.UserName;
            if (photo != null)
            {
                record.FResult = photo.ID.ToString();
                record.ResultName = photo.FilePath;
            }
            record.FState = actionType;
            BLLState.Add(record);
        }

        /// <summary>
        /// 邀请好友
        /// </summary>
        /// <param name="user">用户</param>        
        ///<param name="friend">好友</param>        
        public void CreateInviteFriendState(Model.User_Main user, Model.User_Main friend, int cash)
        {
            int actionType = Convert.ToInt32(Public.EnumConfig.StateActionType.InviteUser);
            record.ActionType = Convert.ToInt32(Jy123.BLL.Public.EnumConfig.StateType.User);
            record.CTime = DateTime.Now;
            record.FUser = user.ID.ToString();
            record.UserName = user.UserName;
            record.FFriend = friend.ID;
            record.FriendName = friend.UserName;
            //将奖励的现金放在FResult字段
            record.FResult = cash.ToString();
            record.FState = actionType;
            BLLState.Add(record);
        }

        public class StateClass
        {
            private string html;
            public string HTML
            {
                get
                {
                    return html;

                }
                set
                {
                    html = value;
                }
            }
            private string strTime;
            public string STRTIME
            {
                get
                {
                    return strTime;
                }
                set
                {
                    strTime = value;
                }
            }
        }

        /// <summary>
        /// 获取动态记录
        /// </summary>
        /// <param name="type">动态的大类型，如果输入为0，那么就获取所有类型的动态</param>
        /// <param name="count">需要获取的数量</param>
        /// <param name="userId">用户ID</param>
        /// <param name="isOnlyMine">true只选择本人的，false选择自己以及好友的</param>
        /// <param name="isOnlyFriend">true只选择好友的，false选择自己以及好友的</param>
        /// isOnlyMine和isOnlyFriend是不可以同时为true的，但是可以同时为false
        /// <param name="stateType">具体的动态类型，如果不需要此功能请输入0</param>
        /// <returns>动态记录List</returns>
        public List<Model.State_Record> GetStateRecord(int type, int count, int userId, bool isOnlyMine, bool isOnlyFriend, int stateType)
        {
            StringBuilder strSQL = new StringBuilder();
            strSQL.AppendFormat("SELECT TOP {0} * FROM State_Record ", count.ToString());
            if (!isOnlyMine && !isOnlyFriend)
            {
                strSQL.AppendFormat("WHERE (FUser LIKE '{0}' OR FFriend LIKE '{0}' OR FUser LIKE '%,{0},%' OR FFriend LIKE '%,{0},%')", userId.ToString());
            }
            else if (isOnlyMine)
            {
                strSQL.AppendFormat("WHERE (FUser LIKE '{0}' OR FUser LIKE '%,{0},%')", userId.ToString());
            }
            else if (isOnlyFriend)
            {
                strSQL.AppendFormat("WHERE (FFriend LIKE '{0}' OR FFriend LIKE '%,{0},%')", userId.ToString());
            }
            if (type > 0)
            {
                strSQL.AppendFormat(" AND ActionType = {0}", type.ToString());
            }
            if (stateType > 0)
            {
                strSQL.AppendFormat(" AND FState = {0}", stateType.ToString());
            }
            strSQL.Append(" ORDER BY CTime DESC ");
            DataSet ds = DbHelperSQL.Query(strSQL.ToString());
            State_Record BLLRecord = new State_Record();
            if (ds.Tables.Count > 0)
            {
                List<Model.State_Record> listRecord = BLLRecord.DataTableToList(ds.Tables[0]);
                return listRecord;
            }
            return null;
        }

        /// <summary>
        /// 获取动态
        /// </summary>
        /// <param name="type">动态的大类型，如果输入为0，那么就获取所有类型的动态</param>
        /// <param name="count">需要获取的数量</param>
        /// <param name="userId">用户ID</param>
        /// <param name="isOnlyMine">true只选择本人的，false选择自己以及好友的</param>
        /// <param name="isOnlyFriend">true只选择好友的，false选择自己以及好友的</param>
        /// isOnlyMine和isOnlyFriend是不可以同时为true的，但是可以同时为false
        /// <param name="stateType">具体的动态类型，如果不需要此功能请输入0</param>
        /// <param name="venuesId">仅用于比赛类型的动态，其他动态请输入0</param>
        /// <returns>StateClass类型的数组,HTML字段为已经构造好的HTML，STRTIME字段为已经构造好的时间字符串</returns>
        public List<StateClass> GetState(int type, int count, int userId, bool isOnlyMine, bool isOnlyFriend, int stateType, int venuesId)
        {
            List<StateClass> result = new List<StateClass>();
            StringBuilder strSQL = new StringBuilder();
            string strCUId = Cookie.getCookie("UserID");
            bool isMe = userId.ToString().Equals(strCUId);
            BLL.User.Friend BLLUserFriend = new Jy123.BLL.User.Friend();
            List<Model.User_Main> listFriends = BLLUserFriend.GetAllFriends(userId);
            strSQL.AppendFormat("SELECT TOP {0} * FROM State_Record ", count.ToString());
            if (!isOnlyMine && !isOnlyFriend)
            {
                strSQL.AppendFormat("WHERE (FUser LIKE '{0}' OR FFriend LIKE '{0}' OR FUser LIKE '%,{0},%' OR FFriend LIKE '%,{0},%')", userId.ToString());
            }
            else if (isOnlyMine)
            {
                if (type == Convert.ToInt32(EnumConfig.StateType.Module))
                {
                    int friendsCount = listFriends.Count;
                    if (friendsCount > 0)
                    {
                        strSQL.AppendFormat("WHERE (FUser LIKE '%,{0},%' ", listFriends[0].ID.ToString());
                        for (int i = 1; i < friendsCount; i++)
                        {
                            strSQL.AppendFormat(" OR FUser LIKE '%,{0},%' ", listFriends[i].ID.ToString());
                        }
                        strSQL.Append(")");
                    }
                    else
                    {
                        strSQL.AppendFormat("WHERE 1 = 0");//No friends no record.
                    }

                }
                else
                {
                    strSQL.AppendFormat("WHERE (FUser LIKE '{0}' OR FUser LIKE '%,{0},%')", userId.ToString());
                }
            }
            else if (isOnlyFriend)
            {
                if (type == Convert.ToInt32(EnumConfig.StateType.Module))
                {
                    strSQL.AppendFormat("WHERE (FFriend LIKE '{0}' OR FFriend LIKE '%,{0},%')", userId.ToString());
                }
                else
                {
                    strSQL.AppendFormat("WHERE (FFriend LIKE '{0}' AND FUser NOT LIKE '{0}')", userId.ToString());
                }
            }
            if (type > 0)
            {
                strSQL.AppendFormat(" AND ActionType = {0}", type.ToString());
            }
            if (stateType > 0)
            {
                strSQL.AppendFormat(" AND FState = {0}", stateType.ToString());
            }
            if (venuesId > 0)
            {
                strSQL.AppendFormat(" AND FVenues = {0}", venuesId.ToString());
            }
            strSQL.Append(" ORDER BY CTime DESC ");
            DataSet ds = DbHelperSQL.Query(strSQL.ToString());
            State_Record BLLRecord = new State_Record();
            Public_State BLLState = new Public_State();
            List<Model.Public_State> listState = BLLState.GetModelList(string.Empty);
            Dictionary<int, Model.Public_State> dicState = new Dictionary<int, Jy123.Model.Public_State>();
            foreach (Model.Public_State state in listState)
            {
                dicState.Add(state.ID, state);
            }
            if (ds.Tables.Count > 0)
            {
                List<Model.State_Record> listRecord = BLLRecord.DataTableToList(ds.Tables[0]);
                User_Photo BLLPhoto = new User_Photo();
                List<Model.User_Photo> listPhoto = BLLPhoto.GetModelList("FUser = " + userId.ToString() + "OR FUser IN (SELECT FFriend FROM User_Friend WHERE FUser = " + userId.ToString() + ")");
                Dictionary<int, Model.User_Photo> dicPhoto = new Dictionary<int, Jy123.Model.User_Photo>();
                foreach (Model.User_Photo photo in listPhoto)
                {
                    dicPhoto.Add(photo.ID, photo);
                }
                Public_Gift BLLGift = new Public_Gift();
                List<Model.Public_Gift> listGift = BLLGift.GetModelList(string.Empty);
                Dictionary<int, Model.Public_Gift> dicGift = new Dictionary<int, Jy123.Model.Public_Gift>();
                foreach (Model.Public_Gift gift in listGift)
                {
                    dicGift.Add(gift.ID, gift);
                }
                Public_JType BLLJType = new Public_JType();
                Public_Level BLLLevel = new Public_Level();
                List<Model.Public_Level> listLevel = BLLLevel.GetModelList(string.Empty);
                List<Model.Public_JType> listJType = BLLJType.GetModelList(string.Empty);
                Dictionary<int, Model.Public_JType> dicJType = new Dictionary<int, Jy123.Model.Public_JType>();
                foreach (Model.Public_JType JType in listJType)
                {
                    dicJType.Add(JType.ID, JType);
                }
                Dictionary<int, Model.Public_Level> dicLevel = new Dictionary<int, Jy123.Model.Public_Level>();
                foreach (Model.Public_Level level in listLevel)
                {
                    dicLevel.Add(level.ID, level);
                }

                foreach (Model.State_Record record in listRecord)
                {
                    StateClass stateClass = new StateClass();
                    Model.Public_State cState = dicState[record.FState];
                    string html = cState.Code;
                    string strUser = "<a href = \"/Home/Index.aspx?UserId=" + record.FUser + "\">" + record.UserName + "</a>";
                    if (record.FFriend.HasValue)
                    {
                        string strFriend = "<a href = \"/Home/Index.aspx?UserId=" + record.FFriend.Value.ToString() + "\">" + record.FriendName + "</a>";
                        if ((userId.ToString().Equals(record.FUser) || userId == record.FFriend.Value) && isMe)
                        {
                            strFriend = "<a>你</a>";
                        }
                        html = html.Replace("$Friend$", strFriend);
                    }

                    if (userId.ToString().Equals(record.FUser) && isMe)
                    {
                        strUser = "<a>你</a>";
                    }
                    html = html.Replace("$User$", strUser);
                    switch (record.FState)
                    {
                        case 1:
                        case 2:
                        case 3:
                        case 4:
                        case 6:
                            string strGuess = "<a href = \"/Guess/GuessInfo.aspx?GuessID=" + record.FResult + "\" >" + record.ResultName + "</a>";
                            html = html.Replace("$Guess$", strGuess);
                            break;
                        case 5:
                            string strCGuess = record.ResultName;
                            html = html.Replace("$Guess$", strCGuess);
                            break;
                        case 7:
                            string strAlbum = "<a href = \"/Album/PhotoFriend.aspx?AlbumId=" + record.FAlbum.Value.ToString() + "\" >" + record.AlbumName + "</a>";
                            html = html.Replace("$Album$", strAlbum);
                            break;
                        case 8:
                            string strFAlbum = record.FAlbum.Value.ToString();
                            string strCAlbum = "<a href = \"/Album/PhotoFriend.aspx?AlbumId=" + strFAlbum + "\" >" + record.AlbumName + "</a>";
                            html = html.Replace("$Album$", strCAlbum);
                            string[] strPList = record.FResult.Split(',');
                            int length = strPList.Length;
                            html = html.Replace("$Count$", length.ToString());

                            int cCount = length;
                            if (cCount > 4)
                            {
                                cCount = 4;
                            }
                            StringBuilder sbString = new StringBuilder();
                            sbString.Append("<br/>");
                            for (int i = 0; i < cCount; i++)
                            {
                                int cPhotoId = int.Parse(strPList[i]);
                                Model.User_Photo cPhoto = dicPhoto[cPhotoId];
                                string strHref = string.Format("<a href = \"/Album/PhotoComment.aspx?AlbumID={0}&PhotoID={1}\"><img width='45px' alt='' src=\"" + cPhoto.FilePath + "\"/></a>", strFAlbum, cPhotoId.ToString());
                                if (!userId.ToString().Equals(record.FUser))
                                {
                                    strHref = string.Format("<a href = \"/Album/PhotoFriendComment.aspx?AlbumID={0}&PhotoID={1}\"><img width='45px' alt='' src=\"" + cPhoto.FilePath + "\"/></a>", strFAlbum, cPhotoId.ToString());
                                }
                                sbString.Append(strHref);
                            }
                            html = html.Replace("$PhotoList$", sbString.ToString());
                            break;
                        case 9:
                            int photoId = record.FAlbum.Value;
                            Model.User_Photo cP = dicPhoto[photoId];

                            string strCHref = string.Format("<a href = \"/Album/PhotoComment.aspx?AlbumID={0}&PhotoID={1}\"><img width='45px'  alt='' src=\"" + cP.FilePath + "\"/></a>", cP.FAlbum.ToString(), photoId.ToString());
                            if (!userId.ToString().Equals(record.FUser))
                            {
                                strCHref = string.Format("<a href = \"/Album/PhotoFriendComment.aspx?AlbumID={0}&PhotoID={1}\"><img width='45px'  alt='' src=\"" + cP.FilePath + "\"/></a>", cP.FAlbum.ToString(), photoId.ToString());
                            }
                            html = html.Replace("$Photo$", strCHref);
                            break;
                        case 10:
                        case 11:
                            string strBlog = "<a href = \"/Blog/BlogDetail.aspx?BlogID=" + record.FResult + "\" >" + record.AlbumName + "</a>";
                            html = html.Replace("$Blog$", strBlog);
                            break;
                        case 12:
                        case 13:
                            string strMoodHref = string.Format("<a href = \"/Mood/MyMood.aspx\">心情</a>");
                            if (!userId.ToString().Equals(record.FUser))
                            {
                                strMoodHref = string.Format("<a href = \"/Mood/FriendMood.aspx\">心情</a>");
                            }
                            html = html.Replace("$Mood$", strMoodHref);
                            break;
                        case 14:
                        case 15:
                            int moduleId = int.Parse(record.FResult);
                            Module_Main BLLModule = new Module_Main();

                            Model.Module_Main module = BLLModule.GetModel(moduleId);
                            Model.Public_JType JType = dicJType[module.FJType.Value];
                            string strModuleHref = string.Format("<a href = \"/Module/Venues/MyVenues.aspx?VenuesId={0}\">" + JType.JName + "</a>", moduleId.ToString());
                            if (JType.JFather.Value == 2)
                            {
                                strModuleHref = string.Format("<a href = \"/Module/Club/MyClub.aspx?ClubIdId={0}\">" + JType.JName + "</a>", moduleId.ToString());
                            }
                            if (JType.JFather.Value == 3)
                            {
                                //string strModuleHref = string.Format("<a href = \"/Module/Club/MyClub.aspx?ClubIdId={0}\">" + JType.JName + "</a>", moduleId.ToString());
                            }
                            html = html.Replace("$Module$", strModuleHref);
                            if (html.Contains("$Level$"))
                            {
                                int levelId = 0;
                                if (JType.JFather.Value == 1)
                                {
                                    Venues_Main BLLVenues = new Venues_Main();
                                    levelId = BLLVenues.GetModel(moduleId).FLevel.Value;
                                }
                                else if (JType.JFather.Value == 2)
                                {
                                    Club_Main BLLClub = new Club_Main();
                                    levelId = BLLClub.GetModel(moduleId).FLevel.Value;
                                }
                                else if (JType.JFather.Value == 3)
                                {
                                    TCenter_Main BLLTCenter = new TCenter_Main();
                                    levelId = BLLTCenter.GetModel(moduleId).FLevel.Value;
                                }
                                Model.Public_Level level = dicLevel[levelId];
                                html = html.Replace("$Level$", level.LName);
                            }
                            break;
                        case 16:
                            StringBuilder sbC = new StringBuilder();
                            string[] strUId = record.FUser.Split(',');
                            string[] strUName = record.UserName.Split(',');
                            string[] strMId = record.FClub.Split(',');
                            string[] strMName = record.ClubName.Split(',');
                            string[] strScore = record.ResultName.Split(',');
                            string strVUser = record.FFriend.Value.ToString();
                            string strVUName = record.FriendName;
                            string strVId = record.FVenues.Value.ToString();
                            string strVName = record.VenuesName;
                            string strScoreResult = string.Empty;
                            for (int i = 0; i < strUId.Length - 1; i++)
                            {
                                if (!string.IsNullOrEmpty(strUId[i]))
                                {
                                    string strUHref = string.Format("<a href = \"/Home/Index.aspx?UserId=" + strUId[i] + "\">" + strUName[i] + "</a>");
                                    string strMHref = string.Format("<a href = \"/Module/Club/MyClub.aspx?ClubId=" + strMId[i] + "\">" + strMName[i] + "</a>");
                                    if (userId.ToString().Equals(strUId[i]) && isMe)
                                    {
                                        strUHref = "<a>你</a>";
                                    }
                                    sbC.Append(strUHref + "的" + strMHref + "、");
                                    strScoreResult = strScoreResult + strScore[i] + ":";
                                }
                            }
                            sbC = sbC.Remove(sbC.Length - 1, 1);
                            string strVHref = string.Format("<a href = \"/Module/Venues/MyVenues.aspx?VenuesId=" + strVId + "\">" + strVName + "</a>");
                            string strVUHref = string.Format("<a href = \"/Home/Index.aspx?UserId=" + strVUser + "\">" + strVUName + "</a>");
                            if (userId == record.FFriend.Value && isMe)
                            {
                                strVUHref = "<a>你</a>";
                            }
                            html = html.Replace("$UserClub$", sbC.ToString());
                            html = html.Replace("$Friend$", strVUHref);
                            html = html.Replace("$Module$", strVHref);
                            html = html.Replace("$Score$", strScoreResult.Substring(0, strScoreResult.Length - 1));
                            break;
                        case 17:

                            Model.Public_Gift gift = dicGift[int.Parse(record.FResult)];
                            string strGiftHref = string.Format("<a href = \"/Gift/ReceiveGift.aspx\"><img width='45px'  alt='' src=\"" + gift.Picture + "\"/></a>");
                            if (userId.ToString().Equals(record.FUser))
                            {
                                strGiftHref = string.Format("<a href = \"/Gift/SendedGift.aspx\"><img width='45px'  alt='' src=\"" + gift.Picture + "\"/></a>");
                            }
                            html = html.Replace("$Gift$", strGiftHref);
                            break;
                        case 19:
                            string strActionHref = string.Format("<a href = \"/Friend/RequestConfirm.aspx\">前去处理</a>");
                            html = html.Replace("$Action$", strActionHref);
                            break;
                        case 20:
                            string strCActionHref = string.Format("<a href=\"javascript:;\" onclick =\"myAjax('/home/FriendAddByUserID.ashx','UserID={0}')\">再次添加</a>", userId.ToString());
                            html = html.Replace("$Action$", strCActionHref);
                            break;
                        case 21:
                        case 22:
                            break;
                        case 23:
                        case 24:
                        case 25:
                            string strVoteHref = string.Format("<a href=\"Vote/VoteJoin.aspx?voteID={0}\">" + record.ResultName + "</a>", record.FResult);
                            html = html.Replace("$Vote$", strVoteHref);
                            break;
                        case 26:
                            html = html.Replace("$UserLevel$", record.ResultName);
                            break;
                        case 27:
                            html = html.Replace("$Cash$", record.FResult);
                            break;
                        case 29:
                            html = html.Replace("$Photo$", "<img width='45px'  alt='' src=\"" + record.ResultName + "\"/>");
                            break;
                        case 30:
                            string strTVUser = record.FFriend.Value.ToString();
                            string strTVUName = record.FriendName;
                            string strTVId = record.FVenues.Value.ToString();
                            string strTVName = record.VenuesName;

                            string strTUHref = string.Format("<a href = \"/Home/Index.aspx?UserId=" + record.FUser + "\">" + record.UserName + "</a>");
                            string strTMHref = string.Format("<a href = \"/Module/Club/MyClub.aspx?ClubId=" + record.FClub + "\">" + record.ClubName + "</a>");
                            if (userId.ToString().Equals(record.FFriend.Value.ToString()) && isMe)
                            {
                                strTUHref = "<a>你</a>";
                            }

                            string strTVHref = string.Format("<a href = \"/Module/Venues/MyVenues.aspx?VenuesId=" + strTVId + "\">" + strTVName + "</a>");
                            string strTVUHref = string.Format("<a href = \"/Home/Index.aspx?UserId=" + strTVUser + "\">" + strTVUName + "</a>");
                            if (userId == int.Parse(record.FUser) && isMe)
                            {
                                strTVUHref = "<a>你</a>";
                            }
                            html = html.Replace("$UserClub$", strTUHref + "的" + strTMHref);
                            html = html.Replace("$Friend$", strTVUHref);
                            html = html.Replace("$Module$", strTVHref);
                            break;
                    }
                    stateClass.HTML = html;
                    stateClass.STRTIME = AboutDateTime.getTimeEXSpan(record.CTime);
                    result.Add(stateClass);
                }
            }
            return result;
        }
    }
}
